package main

import (
	"github.com/gin-gonic/gin"
	"math/rand"
)

const RequestId = "123"

func main() {
	r := gin.Default()
	r.Use(func(c *gin.Context) {
		c.Set(RequestId, rand.Int())
		c.Next()
	})

	r.GET("/itianyu", func(c *gin.Context) {
		h := gin.H{
			"itianyu": "itianyu",
		}
		if rid, exists := c.Get(RequestId); exists {
			h[RequestId] = rid
		}
		c.JSON(200, h)
	})
	r.Run()
}
